package com.ymatou.iapi.godmch.service;

import java.util.List;

import net.sf.json.JSONArray;

import org.json.JSONException;
import org.json.JSONObject;

import com.google.gson.JsonArray;
import com.ymatou.iapi.godmch.parameter.parentInfo;
import com.ymt.base.YmatouBaseCall;
import com.ymttest.utils.EnvSetup;
/**
*邀请码列表Call
*FreeMaker Template自动生成代码
*/
public class listcodeCall extends YmatouBaseCall{
	private static String opurl ="api/code/list";
	
	public listcodeCall() {
		super(EnvSetup.getSystemUrl("godmch_iapi"),opurl,"GET","PARAM");
	}
	@Override
	public void addDefHeader() {
		client.addHeader("Accept","text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}
	
	 public String getStatus1()
		{
			  return getString("status");
		}
			
	    public String getMessage()
		{
			 return getString("msg");
		}
	    
	    public Integer getTotal() throws JSONException
		{
			 return new JSONObject(getString("result").toString()).getInt("total");
		}
	    
	    public JsonArray getCodesList() {
	    	JsonArray jsonArray = null;
			try {
				// jsonArray = JSONArray.fromObject(new JSONObject(getString("result").toString()).getString("codes"));
				
				jsonArray = getJsonObject().get("result").getAsJsonObject().get("codes").getAsJsonArray();

				//data = (List<parentInfo>) FormatUtil.GSONToObject(jsonArray, parentInfo.class);
				//FormatUtil.JSONToObject(new JSONObject(getString("result").toString()).getString("parents"), AllparentsmchResp.class);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return jsonArray;
		}
}